package com.learning.exercise;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;

import com.learning.bean.Joke;

public class Test {
	public static void main(String[] args) {
		List<Joke> list=new ArrayList<Joke>();
		list.add(new Joke("1", "das", "fsdf", "gdsgfrsdg"));
		list.add(new Joke("1", "das", "fsdf", "gdsgfrsdg"));
		list.add(new Joke("1", "das", "fsdf", "gdsgfrsdg"));
		list.add(new Joke("1", "das", "fsdf", "gdsgfrsdg"));
		list.add(new Joke("1", "das", "fsdf", "gdsgfrsdg"));
		try {
			Class.forName("org.sqlite.JDBC");
            String url="jdbc:sqlite:/e:/databases/xiaohua";
            Connection conn=DriverManager.getConnection(url);
            for (Joke j : list) {
            	String sql="insert into Jokes(valid,body,title) values(?,?,?)";
            	PreparedStatement pst=conn.prepareStatement(sql);
//                ResultSet rs=pst.getResultSet();
                pst.setString(1, j.getValid());
                pst.setString(2, j.getBody());
                pst.setString(3, j.getTitle());
                if(pst.executeUpdate()>0)
                	System.out.println("success");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
